package 华为OD机试真题2023.基础题;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;

public class HJ15_通信误码 {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(new File("src/main/java/华为OD机试真题2023/基础题/input/15.txt"));
        int N = in.nextInt();
        List<Integer> list = new ArrayList<>();
        Map<Integer, Integer> map = new HashMap<>();
        //nextInt() 之后不是 nextLine() 的话就不用吸收换行
        int maxNum = 0;
        while (N-- > 0) {
            int num = in.nextInt();
            list.add(num);
            map.put(num, map.getOrDefault(num, 0) + 1);
            maxNum = Math.max(maxNum, map.get(num));
        }
        List<Integer> maxList = new ArrayList<>();
        for (Integer i : map.keySet()) {
            if (map.get(i).equals(maxNum)) {
                maxList.add(i);
            }
        }
        int minNum = Integer.MAX_VALUE;
        for (Integer i : maxList) {
            int tmp = list.lastIndexOf(i) - list.indexOf(i) + 1;
            minNum = Math.min(minNum, tmp);
        }
        System.out.println(minNum);
    }
}
